package cn.arikeky.controller;

import cn.arikeky.basic.util.AjaxResult;
import cn.arikeky.domain.Fiction;
import cn.arikeky.service.FictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/fiction")
public class FictionController {

    @Autowired
    private FictionService fictionService;

    // 查询全部
    @GetMapping
    public List<Fiction> findAll(){
        return fictionService.findFAll();
    }

    // 添加  修改
    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody Fiction fiction){
        if (null == fiction.getF_id()){
            fictionService.addF(fiction);
        } else {
            fictionService.updateF(fiction);
        }
        return  AjaxResult.me().success();
    }

    // 删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        fictionService.deleteF(id);
        return  AjaxResult.me().success();
    }

    // 根据id查询
    @GetMapping("/{id}")
    public Fiction findById(@PathVariable("id") Long id){
        return fictionService.findFById(id);
    }
}
